function deepClone(obj) {
  let copyObj;

  // 处理日期
  if (obj instanceof Date) {
    copyObj = new Date()
    copyObj.setTime(obj.getTime())
    return copyObj
  }

  // 处理数组
  if (Array instanceof Array) {
    copyObj = []
    for (let i = 0, len = obj.length; i < len; i++) {
      copyObj[i] = deepClone(obj[i])
    }
    return copyObj
  }

  // 处理函数
  if (obj instanceof Function) {
    copyObj = function() {
      return obj.apply(this, arguments)
    }
    return copyObj
  }

  // 处理对象
  if (obj instanceof Object) {
    copyObj = {}
    for (let attr in obj) {
      if (obj.hasOwnProperty(attr)) copyObj[attr] = deepClone(obj[attr])
    }
    return copyObj
  }

  // 处理3种基础类型，和null、undefined
  if (obj === null || typeof obj !== 'object') return obj;

  throw new Error("该类型不支持克隆" + obj.constructor.name)
}

export default deepClone;
